/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MasterSupplier.java
 *
 * Created on Aug 9, 2010, 9:39:41 PM
 */
package com.ivanbiz.gui;

import com.ivanbiz.dao.BarangDAO;
import com.ivanbiz.dao.SatuanDAO;
import com.ivanbiz.helper.CenterRenderer;
import com.ivanbiz.helper.RightRenderer;
import com.ivanbiz.helper.ServiceHelper;
import com.ivanbiz.impl.BarangDAOImpl;
import com.ivanbiz.impl.SatuanDAOImpl;
import com.ivanbiz.model.Barang;
import com.ivanbiz.model.Satuan;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Aprisma
 */
public class MasterBarang extends javax.swing.JInternalFrame {

    ServiceHelper serviceHelper = new ServiceHelper();
    BarangDAO barangDAO = new BarangDAOImpl();
    SatuanDAO satuanDAO = new SatuanDAOImpl();
    List<Barang> listBarang = new ArrayList<Barang>();
    List<Satuan> listSatuan = new ArrayList<Satuan>();
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);

    /** Creates new form MasterSupplier */
    public MasterBarang() {
        initComponents();
        updateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        paneCustomer = new javax.swing.JPanel();
        labelKode = new javax.swing.JLabel();
        labelNama = new javax.swing.JLabel();
        labelAlamat = new javax.swing.JLabel();
        labelTelepon = new javax.swing.JLabel();
        labelStock = new javax.swing.JLabel();
        textKode = new javax.swing.JTextField();
        textNama = new javax.swing.JTextField();
        textHargaBaru = new javax.swing.JTextField();
        textStock = new javax.swing.JTextField();
        comboSatuan = new javax.swing.JComboBox();
        panelTombol = new javax.swing.JPanel();
        buttonSimpan = new javax.swing.JButton();
        buttonUbah = new javax.swing.JButton();
        buttonHapus = new javax.swing.JButton();
        buttonReset = new javax.swing.JButton();
        panelCari = new javax.swing.JPanel();
        textCariBarang = new javax.swing.JTextField();
        comboCari = new javax.swing.JComboBox();
        panelDaftarCustomer = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableBarang = new javax.swing.JTable();

        setBorder(new org.jdesktop.swingx.border.DropShadowBorder());
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Master Barang");

        paneCustomer.setBorder(javax.swing.BorderFactory.createTitledBorder("Barang"));

        labelKode.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelKode.setText("Kode");

        labelNama.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelNama.setText("Nama");

        labelAlamat.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelAlamat.setText("Harga");

        labelTelepon.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelTelepon.setText("Satuan");

        labelStock.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelStock.setText("Stock");

        textKode.setFont(new java.awt.Font("Tahoma", 1, 11));

        textNama.setFont(new java.awt.Font("Tahoma", 1, 11));

        textHargaBaru.setFont(new java.awt.Font("Tahoma", 1, 11));

        textStock.setFont(new java.awt.Font("Tahoma", 1, 11));

        comboSatuan.setFont(new java.awt.Font("Tahoma", 1, 11));
        comboSatuan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout paneCustomerLayout = new javax.swing.GroupLayout(paneCustomer);
        paneCustomer.setLayout(paneCustomerLayout);
        paneCustomerLayout.setHorizontalGroup(
            paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneCustomerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelTelepon)
                    .addComponent(labelNama)
                    .addComponent(labelKode)
                    .addComponent(labelAlamat)
                    .addComponent(labelStock))
                .addGap(15, 15, 15)
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textStock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
                    .addComponent(textNama, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
                    .addComponent(textKode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
                    .addComponent(textHargaBaru, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
                    .addComponent(comboSatuan, 0, 560, Short.MAX_VALUE))
                .addContainerGap())
        );
        paneCustomerLayout.setVerticalGroup(
            paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneCustomerLayout.createSequentialGroup()
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelKode))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNama))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textHargaBaru, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelAlamat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboSatuan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelepon))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paneCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textStock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelStock))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        panelTombol.setBorder(javax.swing.BorderFactory.createTitledBorder("Tombol"));

        buttonSimpan.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonSimpan.setText("Simpan");
        buttonSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSimpanActionPerformed(evt);
            }
        });

        buttonUbah.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonUbah.setText("Ubah");
        buttonUbah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonUbahActionPerformed(evt);
            }
        });

        buttonHapus.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonHapus.setText("Hapus");
        buttonHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonHapusActionPerformed(evt);
            }
        });

        buttonReset.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonReset.setText("Reset");
        buttonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelTombolLayout = new javax.swing.GroupLayout(panelTombol);
        panelTombol.setLayout(panelTombolLayout);
        panelTombolLayout.setHorizontalGroup(
            panelTombolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTombolLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTombolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonSimpan, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                    .addComponent(buttonUbah, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                    .addComponent(buttonHapus, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                    .addComponent(buttonReset, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelTombolLayout.setVerticalGroup(
            panelTombolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTombolLayout.createSequentialGroup()
                .addComponent(buttonSimpan)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonUbah)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonHapus)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonReset)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        panelCari.setBorder(javax.swing.BorderFactory.createTitledBorder("Cari Barang"));

        textCariBarang.setFont(new java.awt.Font("Tahoma", 1, 11));
        textCariBarang.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textCariBarangKeyReleased(evt);
            }
        });

        comboCari.setFont(new java.awt.Font("Tahoma", 1, 11));
        comboCari.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout panelCariLayout = new javax.swing.GroupLayout(panelCari);
        panelCari.setLayout(panelCariLayout);
        panelCariLayout.setHorizontalGroup(
            panelCariLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCariLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comboCari, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textCariBarang, javax.swing.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE))
        );
        panelCariLayout.setVerticalGroup(
            panelCariLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCariLayout.createSequentialGroup()
                .addGroup(panelCariLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textCariBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboCari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDaftarCustomer.setBorder(javax.swing.BorderFactory.createTitledBorder("Daftar Barang"));

        tableBarang.setAutoCreateRowSorter(true);
        tableBarang.setFont(new java.awt.Font("Tahoma", 1, 11));
        tableBarang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableBarang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableBarangMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableBarang);

        javax.swing.GroupLayout panelDaftarCustomerLayout = new javax.swing.GroupLayout(panelDaftarCustomer);
        panelDaftarCustomer.setLayout(panelDaftarCustomerLayout);
        panelDaftarCustomerLayout.setHorizontalGroup(
            panelDaftarCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDaftarCustomerLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 734, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelDaftarCustomerLayout.setVerticalGroup(
            panelDaftarCustomerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDaftarCustomerLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelDaftarCustomer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(paneCustomer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(panelTombol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(panelCari, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(panelTombol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(paneCustomer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCari, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDaftarCustomer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-550)/2, 800, 550);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonHapusActionPerformed
        try {
            Barang barang = (Barang) listBarang.get(tableBarang.getSelectedRow());
            barangDAO.delete(barang);
            updateData();
        } catch (Exception ex) {
            Logger.getLogger(MasterBarang.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_buttonHapusActionPerformed

    private void buttonSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSimpanActionPerformed
        try {
            if (textKode.getText().equals("") || textNama.getText().equals("") || textHargaBaru.getText().equals("") || textStock.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Data Belum Lengkap !!!");
            } else {
                Barang barangKode = (Barang) barangDAO.getDataByEqual(Barang.class, "kode", textKode.getText().toUpperCase());
                Barang barangNama = (Barang) barangDAO.getDataByEqual(Barang.class, "nama", textNama.getText().toUpperCase());
                if (barangKode != null && barangNama != null) {
                    JOptionPane.showMessageDialog(null, "Kode Dan Nama Sudah Ada !!!");
                } else {
                    Barang barang = new Barang();
                    barang.setKode(textKode.getText().toUpperCase());
                    barang.setNama(textNama.getText().toUpperCase());
                    barang.setHarga(Double.parseDouble(textHargaBaru.getText().toUpperCase()));
                    barang.setHargaTerakhir(0.0);
                    barang.setSatuan((Satuan) listSatuan.get(comboSatuan.getSelectedIndex()));
                    barang.setStock(Float.parseFloat(textStock.getText().toUpperCase()));
                    barang.setCreateDate(new Date());
                    barangDAO.save(barang);
                    updateData();
                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Format Harga atau Stock Harus Angka !!!");
            Logger.getLogger(MasterBarang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonSimpanActionPerformed

    private void textCariBarangKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textCariBarangKeyReleased
        try {
            listBarang = barangDAO.getDataByLike(Barang.class, comboCari.getSelectedItem().toString(), textCariBarang.getText());
            updateTableBarang();
        } catch (Exception ex) {
            Logger.getLogger(MasterBarang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_textCariBarangKeyReleased

    private void tableBarangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableBarangMouseClicked
        textKode.setEditable(false);
        buttonSimpan.setEnabled(false);
        buttonHapus.setEnabled(true);
        buttonUbah.setEnabled(true);
        Barang barang = (Barang) listBarang.get(tableBarang.getSelectedRow());
        textKode.setText(barang.getKode());
        textNama.setText(barang.getNama());
        textHargaBaru.setText("" + barang.getHarga());
        textStock.setText("" + barang.getStock());
        comboSatuan.setSelectedItem(barang.getSatuan().getKode() + " (" + barang.getSatuan().getNama() + ")");
    }//GEN-LAST:event_tableBarangMouseClicked

    private void buttonUbahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUbahActionPerformed
        try {
            if (textKode.getText().equals("") || textNama.getText().equals("") || textHargaBaru.getText().equals("") || textStock.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "Data Belum Lengkap !!!");
            } else {
//                Barang barangNama = (Barang) barangDAO.getDataByEqual(Barang.class, "nama", textNama.getText().toUpperCase());
//                if (barangNama != null) {
//                    JOptionPane.showMessageDialog(null, "Nama Sudah Ada !!!");
//                } else {
                Barang barang = (Barang) listBarang.get(tableBarang.getSelectedRow());
                if (barang.getHarga() == Double.parseDouble(textHargaBaru.getText().toUpperCase())) {
                    barang.setKode(textKode.getText().toUpperCase());
                    barang.setNama(textNama.getText().toUpperCase());
                    barang.setSatuan((Satuan) listSatuan.get(comboSatuan.getSelectedIndex()));
                    barang.setStock(Float.parseFloat(textStock.getText().toUpperCase()));
                    barang.setCreateDate(new Date());
                    barangDAO.update(barang);
                    updateData();
                } else {
                    barang.setKode(textKode.getText().toUpperCase());
                    barang.setNama(textNama.getText().toUpperCase());
                    barang.setHargaTerakhir(barang.getHarga());
                    barang.setHarga(Double.parseDouble(textHargaBaru.getText().toUpperCase()));
                    barang.setSatuan((Satuan) listSatuan.get(comboSatuan.getSelectedIndex()));
                    barang.setStock(Float.parseFloat(textStock.getText().toUpperCase()));
                    barang.setCreateDate(new Date());
                    barangDAO.update(barang);
                    updateData();
                }
//                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Format Harga atau Stock Harus Angka !!!");
            Logger.getLogger(MasterBarang.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonUbahActionPerformed

    private void buttonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetActionPerformed
        updateData();
    }//GEN-LAST:event_buttonResetActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonHapus;
    private javax.swing.JButton buttonReset;
    private javax.swing.JButton buttonSimpan;
    private javax.swing.JButton buttonUbah;
    private javax.swing.JComboBox comboCari;
    private javax.swing.JComboBox comboSatuan;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelAlamat;
    private javax.swing.JLabel labelKode;
    private javax.swing.JLabel labelNama;
    private javax.swing.JLabel labelStock;
    private javax.swing.JLabel labelTelepon;
    private javax.swing.JPanel paneCustomer;
    private javax.swing.JPanel panelCari;
    private javax.swing.JPanel panelDaftarCustomer;
    private javax.swing.JPanel panelTombol;
    private javax.swing.JTable tableBarang;
    private javax.swing.JTextField textCariBarang;
    private javax.swing.JTextField textHargaBaru;
    private javax.swing.JTextField textKode;
    private javax.swing.JTextField textNama;
    private javax.swing.JTextField textStock;
    // End of variables declaration//GEN-END:variables

    private void updateComboCari() {
        Object[] dataClass = serviceHelper.getPropertyClass(Barang.class);
        Object[] dataSearch = new Object[3];
        dataSearch[0] = dataClass[1];
        dataSearch[1] = dataClass[2];
        dataSearch[2] = dataClass[6];
        comboCari.setModel(new DefaultComboBoxModel(dataSearch));
    }
    // End of variables declaration

    private void updateComboSatuan() {
        Object data[] = new Object[listSatuan.size()];
        int x = 0;
        for (Satuan satuan : listSatuan) {
            data[x] = satuan.getKode() + " (" + satuan.getNama() + ")";
            x++;
        }
        comboSatuan.setModel(new DefaultComboBoxModel(data));
    }

    private void updateData() {
        try {
            buttonUbah.setEnabled(false);
            buttonHapus.setEnabled(false);
            textKode.setEditable(true);
            buttonSimpan.setEnabled(true);
            textKode.setText("");
            textNama.setText("");
            textHargaBaru.setText("");
            textStock.setText("");
            listSatuan = satuanDAO.getAll(Satuan.class);
            updateComboSatuan();
            listBarang = barangDAO.getAll(Barang.class);
            updateTableBarang();
            updateComboCari();
        } catch (Exception ex) {
            Logger.getLogger(MasterBarang.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    private void updateTableBarang() {
        String[] judul = {"No", "Kode", "Nama", "Harga", "Harga Lama", "Satuan", "Stock"};
        Object[][] isi = new Object[listBarang.size()][7];
        int x = 0;
        int no = 0;
        for (Barang barang : listBarang) {
            isi[x][0] = no += 1;
            isi[x][1] = barang.getKode();
            isi[x][2] = barang.getNama();
            isi[x][3] = "Rp " + numberFormat.format(barang.getHarga()) + ",00";
            isi[x][4] = "Rp " + numberFormat.format(barang.getHargaTerakhir()) + ",00";
            isi[x][5] = barang.getSatuan().getNama();
            isi[x][6] = barang.getStock();
            x++;
        }
        tableBarang.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tableBarang.getColumnModel().getColumn(0);
        column0.setPreferredWidth(75);
        column0.setMaxWidth(75);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tableBarang.getColumnModel().getColumn(1);
        column1.setPreferredWidth(125);
        //column1.setMaxWidth(125);
        column1.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tableBarang.getColumnModel().getColumn(3);
        column3.setPreferredWidth(140);
        column3.setMaxWidth(140);
        column3.setCellRenderer(new RightRenderer());
        TableColumn column4 = tableBarang.getColumnModel().getColumn(4);
        column4.setPreferredWidth(140);
        column4.setMaxWidth(140);
        column4.setCellRenderer(new RightRenderer());
        TableColumn column5 = tableBarang.getColumnModel().getColumn(5);
        column5.setPreferredWidth(100);
        column5.setMaxWidth(100);
        column5.setCellRenderer(new CenterRenderer());
        TableColumn column6 = tableBarang.getColumnModel().getColumn(6);
        column6.setPreferredWidth(75);
        column6.setMaxWidth(75);
        column6.setCellRenderer(new CenterRenderer());
    }
}
